#include "../Public/Sphere.h"


bool CSphere::ray_interset(const Vec3f& orig, const Vec3f& dir, float& t) const
{
	Vec3f L = center - orig;
	float tca = L * dir;
	float d2 = L * L - tca * tca;
	if (d2 > radius * radius) 
		return false;
	float thc = sqrtf(radius * radius - d2);
	t = tca - thc;
	float t1 = tca + thc;
	if (t < 0) 
		t = t1;
	if (t < 0) 
		return false;

	return true;
}

